package com.example.musicplayer;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ViewFlipper;

/**
 * Created by asd on 2016/8/25.
 */
public class Fragment_2 extends Fragment{
    private int [] id = {R.drawable.q,R.drawable.w,R.drawable.e,R.drawable.r,R.drawable.t,R.drawable.y};
    private ViewFlipper vf;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View view = inflater.inflate(R.layout.fragment_2,null);
        init(view);
        return view;
    }

    private void init(View view) {
        vf = (ViewFlipper) view.findViewById(R.id.vf);
        //循环遍历加载图片
        for(int i = 0;i<id.length;i++){
            vf.addView(getImage(id[i],view));
        }

        vf.setFlipInterval(2500);
        vf.startFlipping();
    }
    private ImageView getImage(int Id,View view){
        ImageView img = new ImageView(view.getContext());
        img.setImageResource(Id);
        return img;
    }
}
